var CreateTable = {
    server: null,
    db: null,
    fields: 1,
    indexfields: 4,
    Modal: function( which ) {
        var node = which.cloneNode( true );
        node.style.display = '';
        Modals.Create( node, 300, 145 );
        tableInput = node.getElementsByTagName( 'input' )[ 0 ];
        setTimeout( function() {
            tableInput.select();
            tableInput.focus();
        }, 100 );
    },
    Go: function( modal ) {
        var name = modal.getElementsByTagName( 'input' )[ 0 ].value;
        window.location = '?p=newtable&server=' + this.server + '&database=' + this.db + '&table=' + name;
    },
    AddField: function( which ) {
        var node = which.cloneNode( true );
        var par = which.parentNode;
        if ( which.previousSibling.className != 't' ) {
            node.className = 't';
        }
        node.style.opacity = 0;
        node.style.display = '';
        par.insertBefore( node, which );
        Animations.Create( node, 'opacity', 2000, 0, 1 );
        
        ++this.fields;
        if ( this.fields + ( this.indexfields * 0.75 ) >= 11 ) {
            Postinfo.SetPosition( 'relative' );
        }
    },
    RemoveField: function( which ) {
        var table = which.parentNode;
        table.removeChild( which );
        FixTableRows( table );

        --this.fields;
        if ( this.fields + ( this.indexfields * 0.75 ) <= 10 ) {
            Postinfo.SetPosition( 'absolute' );
        }
    },
    AddIndex: function( indextable ) {
        var node = nextObject( indextable ).cloneNode( true );
        node.style.display = '';
        Modals.Create( node, 300, 200 );
    }
};
